#include "StdAfx.h"
#include "Manage.h"
#include "Suit.h"
#include "Prepare.h"
#include "SerialCheck.h"
#include "EnvironmentCheck.h"
Manage::Manage(void)
	: is_need_run_(false)
{
}

Manage::~Manage(void)
{
}

Manage& Manage::getInstance()
{
	static Manage manage;
	return manage;
}

bool Manage::prepare()
{
	Prepare preparer;

	preparer.addCheck(new EnvironmentCheck());
	preparer.addCheck(new SerialCheck());

	return preparer.run(NULL);
}

bool Manage::run(void* param)
{
	for (std::vector<Suit*>::iterator iter=m_suits.begin(); iter!=m_suits.end();++iter)
	{
		if ((*iter)!=NULL)
		{
			if (!(*iter)->run(param))
			{
				return false;
			}
		}
	}
	return true;
}

bool Manage::unPrepare()
{
	return true;
}

bool Manage::addSuit(Suit* suit)
{
	if (suit==NULL)
	{
		return false;
	}
	m_suits.push_back(suit);

	return true;
}

bool Manage::delSuit(int index)
{
	if (index >= m_suits.size())
	{
		return false;
	}

	int id_of_list = 0;
	for (std::vector<Suit*>::iterator iter=m_suits.begin();iter!=m_suits.end();++iter,++id_of_list)
	{
		if (index == id_of_list)
		{
			m_suits.erase(iter);
			break;
		}
	}

	return true;
}

std::vector<Suit *> Manage::getSuits()
{
	return m_suits;
}
